
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 3/29/2013 2:25:55 PM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace DNNspot.LiveChat.DataModel
{
	/// <summary>
	/// Encapsulates the 'DNNspot_LiveChat_Messages' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(Message))]	
	[XmlType("Message")]
	public partial class Message : esMessage
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new Message();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Int32 messageId)
		{
			var obj = new Message();
			obj.MessageId = messageId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Int32 messageId, esSqlAccessType sqlAccessType)
		{
			var obj = new Message();
			obj.MessageId = messageId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("MessageCollection")]
	public partial class MessageCollection : esMessageCollection, IEnumerable<Message>
	{
		public Message FindByPrimaryKey(System.Int32 messageId)
		{
			return this.SingleOrDefault(e => e.MessageId == messageId);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(Message))]
		public class MessageCollectionWCFPacket : esCollectionWCFPacket<MessageCollection>
		{
			public static implicit operator MessageCollection(MessageCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator MessageCollectionWCFPacket(MessageCollection collection)
			{
				return new MessageCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class MessageQuery : esMessageQuery
	{
		public MessageQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "MessageQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(MessageQuery query)
		{
			return MessageQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator MessageQuery(string query)
		{
			return (MessageQuery)MessageQuery.SerializeHelper.FromXml(query, typeof(MessageQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esMessage : esEntity
	{
		public esMessage()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 messageId)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(messageId);
			else
				return LoadByPrimaryKeyStoredProcedure(messageId);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 messageId)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(messageId);
			else
				return LoadByPrimaryKeyStoredProcedure(messageId);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 messageId)
		{
			MessageQuery query = new MessageQuery();
			query.Where(query.MessageId == messageId);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 messageId)
		{
			esParameters parms = new esParameters();
			parms.Add("MessageId", messageId);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.PortalId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? PortalId
		{
			get
			{
				return base.GetSystemInt32(MessageMetadata.ColumnNames.PortalId);
			}
			
			set
			{
				if(base.SetSystemInt32(MessageMetadata.ColumnNames.PortalId, value))
				{
					OnPropertyChanged(MessageMetadata.PropertyNames.PortalId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.MessageId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? MessageId
		{
			get
			{
				return base.GetSystemInt32(MessageMetadata.ColumnNames.MessageId);
			}
			
			set
			{
				if(base.SetSystemInt32(MessageMetadata.ColumnNames.MessageId, value))
				{
					OnPropertyChanged(MessageMetadata.PropertyNames.MessageId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.SessionId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? SessionId
		{
			get
			{
				return base.GetSystemInt32(MessageMetadata.ColumnNames.SessionId);
			}
			
			set
			{
				if(base.SetSystemInt32(MessageMetadata.ColumnNames.SessionId, value))
				{
					this._UpToSessionBySessionId = null;
					this.OnPropertyChanged("UpToSessionBySessionId");
					OnPropertyChanged(MessageMetadata.PropertyNames.SessionId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.AgentId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? AgentId
		{
			get
			{
				return base.GetSystemInt32(MessageMetadata.ColumnNames.AgentId);
			}
			
			set
			{
				if(base.SetSystemInt32(MessageMetadata.ColumnNames.AgentId, value))
				{
					this._UpToAgentByAgentId = null;
					this.OnPropertyChanged("UpToAgentByAgentId");
					OnPropertyChanged(MessageMetadata.PropertyNames.AgentId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.ClientId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? ClientId
		{
			get
			{
				return base.GetSystemInt32(MessageMetadata.ColumnNames.ClientId);
			}
			
			set
			{
				if(base.SetSystemInt32(MessageMetadata.ColumnNames.ClientId, value))
				{
					this._UpToClientByClientId = null;
					this.OnPropertyChanged("UpToClientByClientId");
					OnPropertyChanged(MessageMetadata.PropertyNames.ClientId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.Body
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Body
		{
			get
			{
				return base.GetSystemString(MessageMetadata.ColumnNames.Body);
			}
			
			set
			{
				if(base.SetSystemString(MessageMetadata.ColumnNames.Body, value))
				{
					OnPropertyChanged(MessageMetadata.PropertyNames.Body);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Messages.CreatedDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreatedDate
		{
			get
			{
				return base.GetSystemDateTime(MessageMetadata.ColumnNames.CreatedDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(MessageMetadata.ColumnNames.CreatedDate, value))
				{
					OnPropertyChanged(MessageMetadata.PropertyNames.CreatedDate);
				}
			}
		}		
		
		[CLSCompliant(false)]
		internal protected Agent _UpToAgentByAgentId;
		[CLSCompliant(false)]
		internal protected Client _UpToClientByClientId;
		[CLSCompliant(false)]
		internal protected Session _UpToSessionBySessionId;
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "PortalId": this.str().PortalId = (string)value; break;							
						case "MessageId": this.str().MessageId = (string)value; break;							
						case "SessionId": this.str().SessionId = (string)value; break;							
						case "AgentId": this.str().AgentId = (string)value; break;							
						case "ClientId": this.str().ClientId = (string)value; break;							
						case "Body": this.str().Body = (string)value; break;							
						case "CreatedDate": this.str().CreatedDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "PortalId":
						
							if (value == null || value is System.Int32)
								this.PortalId = (System.Int32?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.PortalId);
							break;
						
						case "MessageId":
						
							if (value == null || value is System.Int32)
								this.MessageId = (System.Int32?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.MessageId);
							break;
						
						case "SessionId":
						
							if (value == null || value is System.Int32)
								this.SessionId = (System.Int32?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.SessionId);
							break;
						
						case "AgentId":
						
							if (value == null || value is System.Int32)
								this.AgentId = (System.Int32?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.AgentId);
							break;
						
						case "ClientId":
						
							if (value == null || value is System.Int32)
								this.ClientId = (System.Int32?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.ClientId);
							break;
						
						case "CreatedDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedDate = (System.DateTime?)value;
								OnPropertyChanged(MessageMetadata.PropertyNames.CreatedDate);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esMessage entity)
			{
				this.entity = entity;
			}
			
	
			public System.String PortalId
			{
				get
				{
					System.Int32? data = entity.PortalId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.PortalId = null;
					else entity.PortalId = Convert.ToInt32(value);
				}
			}
				
			public System.String MessageId
			{
				get
				{
					System.Int32? data = entity.MessageId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.MessageId = null;
					else entity.MessageId = Convert.ToInt32(value);
				}
			}
				
			public System.String SessionId
			{
				get
				{
					System.Int32? data = entity.SessionId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.SessionId = null;
					else entity.SessionId = Convert.ToInt32(value);
				}
			}
				
			public System.String AgentId
			{
				get
				{
					System.Int32? data = entity.AgentId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.AgentId = null;
					else entity.AgentId = Convert.ToInt32(value);
				}
			}
				
			public System.String ClientId
			{
				get
				{
					System.Int32? data = entity.ClientId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ClientId = null;
					else entity.ClientId = Convert.ToInt32(value);
				}
			}
				
			public System.String Body
			{
				get
				{
					System.String data = entity.Body;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Body = null;
					else entity.Body = Convert.ToString(value);
				}
			}
				
			public System.String CreatedDate
			{
				get
				{
					System.DateTime? data = entity.CreatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedDate = null;
					else entity.CreatedDate = Convert.ToDateTime(value);
				}
			}
			

			private esMessage entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return MessageMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public MessageQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new MessageQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(MessageQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(MessageQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private MessageQuery query;		
	}



	[Serializable]
	abstract public partial class esMessageCollection : esEntityCollection<Message>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return MessageMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "MessageCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public MessageQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new MessageQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(MessageQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new MessageQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(MessageQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((MessageQuery)query);
		}

		#endregion
		
		private MessageQuery query;
	}



	[Serializable]
	abstract public partial class esMessageQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return MessageMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "PortalId": return this.PortalId;
				case "MessageId": return this.MessageId;
				case "SessionId": return this.SessionId;
				case "AgentId": return this.AgentId;
				case "ClientId": return this.ClientId;
				case "Body": return this.Body;
				case "CreatedDate": return this.CreatedDate;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem PortalId
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.PortalId, esSystemType.Int32); }
		} 
		
		public esQueryItem MessageId
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.MessageId, esSystemType.Int32); }
		} 
		
		public esQueryItem SessionId
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.SessionId, esSystemType.Int32); }
		} 
		
		public esQueryItem AgentId
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.AgentId, esSystemType.Int32); }
		} 
		
		public esQueryItem ClientId
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.ClientId, esSystemType.Int32); }
		} 
		
		public esQueryItem Body
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.Body, esSystemType.String); }
		} 
		
		public esQueryItem CreatedDate
		{
			get { return new esQueryItem(this, MessageMetadata.ColumnNames.CreatedDate, esSystemType.DateTime); }
		} 
		
		#endregion
		
	}


	
	public partial class Message : esMessage
	{

				
		#region UpToAgentByAgentId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - FK_DNNspot_LiveChat_Messages_DNNspot_LiveChat_Agents
		/// </summary>

		[XmlIgnore]
					
		public Agent UpToAgentByAgentId
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._UpToAgentByAgentId == null && AgentId != null)
				{
					this._UpToAgentByAgentId = new Agent();
					this._UpToAgentByAgentId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToAgentByAgentId", this._UpToAgentByAgentId);
					this._UpToAgentByAgentId.Query.Where(this._UpToAgentByAgentId.Query.AgentId == this.AgentId);
					this._UpToAgentByAgentId.Query.Load();
				}	
				return this._UpToAgentByAgentId;
			}
			
			set
			{
				this.RemovePreSave("UpToAgentByAgentId");
				

				if(value == null)
				{
					this.AgentId = null;
					this._UpToAgentByAgentId = null;
				}
				else
				{
					this.AgentId = value.AgentId;
					this._UpToAgentByAgentId = value;
					this.SetPreSave("UpToAgentByAgentId", this._UpToAgentByAgentId);
				}
				
			}
		}
		#endregion
		

				
		#region UpToClientByClientId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - FK_DNNspot_LiveChat_Messages_DNNspot_LiveChat_Clients
		/// </summary>

		[XmlIgnore]
					
		public Client UpToClientByClientId
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._UpToClientByClientId == null && ClientId != null)
				{
					this._UpToClientByClientId = new Client();
					this._UpToClientByClientId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToClientByClientId", this._UpToClientByClientId);
					this._UpToClientByClientId.Query.Where(this._UpToClientByClientId.Query.ClientId == this.ClientId);
					this._UpToClientByClientId.Query.Load();
				}	
				return this._UpToClientByClientId;
			}
			
			set
			{
				this.RemovePreSave("UpToClientByClientId");
				

				if(value == null)
				{
					this.ClientId = null;
					this._UpToClientByClientId = null;
				}
				else
				{
					this.ClientId = value.ClientId;
					this._UpToClientByClientId = value;
					this.SetPreSave("UpToClientByClientId", this._UpToClientByClientId);
				}
				
			}
		}
		#endregion
		

				
		#region UpToSessionBySessionId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - FK_DNNspot_LiveChat_Messages_DNNspot_LiveChat_Sessions
		/// </summary>

		[XmlIgnore]
					
		public Session UpToSessionBySessionId
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._UpToSessionBySessionId == null && SessionId != null)
				{
					this._UpToSessionBySessionId = new Session();
					this._UpToSessionBySessionId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToSessionBySessionId", this._UpToSessionBySessionId);
					this._UpToSessionBySessionId.Query.Where(this._UpToSessionBySessionId.Query.SessionId == this.SessionId);
					this._UpToSessionBySessionId.Query.Load();
				}	
				return this._UpToSessionBySessionId;
			}
			
			set
			{
				this.RemovePreSave("UpToSessionBySessionId");
				

				if(value == null)
				{
					this.SessionId = null;
					this._UpToSessionBySessionId = null;
				}
				else
				{
					this.SessionId = value.SessionId;
					this._UpToSessionBySessionId = value;
					this.SetPreSave("UpToSessionBySessionId", this._UpToSessionBySessionId);
				}
				
			}
		}
		#endregion
		

		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
			if(!this.es.IsDeleted && this._UpToAgentByAgentId != null)
			{
				this.AgentId = this._UpToAgentByAgentId.AgentId;
			}
			if(!this.es.IsDeleted && this._UpToClientByClientId != null)
			{
				this.ClientId = this._UpToClientByClientId.ClientId;
			}
			if(!this.es.IsDeleted && this._UpToSessionBySessionId != null)
			{
				this.SessionId = this._UpToSessionBySessionId.SessionId;
			}
		}
		
	}
	



	[Serializable]
	public partial class MessageMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected MessageMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(MessageMetadata.ColumnNames.PortalId, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = MessageMetadata.PropertyNames.PortalId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.MessageId, 1, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = MessageMetadata.PropertyNames.MessageId;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 10;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.SessionId, 2, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = MessageMetadata.PropertyNames.SessionId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.AgentId, 3, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = MessageMetadata.PropertyNames.AgentId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.ClientId, 4, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = MessageMetadata.PropertyNames.ClientId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.Body, 5, typeof(System.String), esSystemType.String);
			c.PropertyName = MessageMetadata.PropertyNames.Body;
			c.CharacterMaxLength = 1073741823;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(MessageMetadata.ColumnNames.CreatedDate, 6, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = MessageMetadata.PropertyNames.CreatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public MessageMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string MessageId = "MessageId";
			 public const string SessionId = "SessionId";
			 public const string AgentId = "AgentId";
			 public const string ClientId = "ClientId";
			 public const string Body = "Body";
			 public const string CreatedDate = "CreatedDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string MessageId = "MessageId";
			 public const string SessionId = "SessionId";
			 public const string AgentId = "AgentId";
			 public const string ClientId = "ClientId";
			 public const string Body = "Body";
			 public const string CreatedDate = "CreatedDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(MessageMetadata))
			{
				if(MessageMetadata.mapDelegates == null)
				{
					MessageMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (MessageMetadata.meta == null)
				{
					MessageMetadata.meta = new MessageMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("PortalId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("MessageId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("SessionId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("AgentId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("ClientId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Body", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreatedDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				meta.Source = "DNNspot_LiveChat_Messages";
				meta.Destination = "DNNspot_LiveChat_Messages";
				
				meta.spInsert = "proc_DNNspot_LiveChat_MessagesInsert";				
				meta.spUpdate = "proc_DNNspot_LiveChat_MessagesUpdate";		
				meta.spDelete = "proc_DNNspot_LiveChat_MessagesDelete";
				meta.spLoadAll = "proc_DNNspot_LiveChat_MessagesLoadAll";
				meta.spLoadByPrimaryKey = "proc_DNNspot_LiveChat_MessagesLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private MessageMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
